<?php

use Illuminate\Database\Seeder;
use App\Models\User;
use App\Models\Goods;
use Faker\Generator as Faker;




class GoodsTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run(Faker $faker)
    {
        foreach (User::get() as $v) {
            // 创建用户商品数据 ， 写入数据库
            $goods = factory(Goods::class)->times(random_int(2,5))->make()
                ->each(function($query) use ($v ,$faker){
                $query->user_id = $v->id;
                $query->goods_code = \Str::random(18);
            });

            // 写入数据库
            $goods->each(function($query){
                Goods::create($query->toArray());
            });
        }
    }
}
